package com.ep.commonbaseadapter;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.widget.ListView;
import android.widget.TextView;

import com.ep.commonbaseadapter.base.SingleItemTypeBaseAdapter;
import com.ep.commonbaseadapter.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/7/31.
 */

public class SingleActivity extends AppCompatActivity {
    private ListView mListView;
    private TextView mTvEmptyView;
    private List<String> mDatas;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_multi);
        mListView= (ListView) findViewById(R.id.lv_multi);
        mTvEmptyView= (TextView) findViewById(R.id.tv_empty);
     //   initDatas();
        mListView.addHeaderView(LayoutInflater.from(this).inflate(R.layout.adapter_header_item,null));//添加的头部跟尾部不能跟setEmptyView()共存?
        mListView.setDivider(null);

        SingleAdapter singleAdapter = new SingleAdapter(this, R.layout.adapter_single_item);
        singleAdapter.setDatas(mDatas);
        mListView.setAdapter(singleAdapter);
        mListView.setEmptyView(mTvEmptyView);

    }

    private void initDatas() {
        mDatas=new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            mDatas.add("test"+i);
        }
    }

    class SingleAdapter extends SingleItemTypeBaseAdapter<String>{

        public SingleAdapter(Context context, int layoutId) {
            super(context, layoutId);
        }

        @Override
        protected void bindData(ViewHolder viewHolder, String data, int position) {
            viewHolder.setText(R.id.tv_content,data);
        }
    }
}
